import type { Ref } from "vue";
/**
 *
 * @param idKey id key值
 * @returns
 * selectionList： 选择的checkbox
 * ids： 选择的对象id集合 ‘，’分割
 * selectionChange：checkbox改变事件
 */
export default function (idKye = "id") {
  /*selection*/
  const selectionList: Ref<any[]> = ref([]);
  const selectionChange = (list: any[]) => {
    selectionList.value = list;
  };
  const ids = computed(() => {
    const ids: string[] = [];
    selectionList.value.forEach((ele: any) => {
      if (ele?.id) {
        ids.push(ele[idKye]);
      }
    });
    return ids.join(",");
  });
  return {
    selectionList,
    selectionChange,
    ids,
  };
}
